package com.jeejam.product.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.jeejam.framework.base.pojo.Pager;
import com.jeejam.product.pojo.Brand;
import com.jeejam.product.sdk.api.IBrandService;
import com.jeejam.product.sdk.dto.BrandDto;
import com.jeejam.product.service.BrandService;
import com.jeejam.util.ShopBeanBuildUtil;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by JACKEY on 2016/3/18.
 */
@Service(version = "1.0.0")
public class BrandDubboService implements IBrandService {

    @Resource
    private BrandService brandService;

    @Override
    public int counts() {
        return brandService.counts();
    }

    @Override
    public Pager getPager(int currentPage, int pageSize) {
        return brandService.getPager(currentPage, pageSize);
    }

    @Override
    public List<BrandDto> findAllByPage(int currentPage, int pageSize) {
        List<Brand> brandList = brandService.selectAllByPage(currentPage, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(brandList, BrandDto.class);
    }

    @Override
    public List<BrandDto> findAll() {
        List<Brand> brandList = brandService.findAll();
        return ShopBeanBuildUtil.slmCopyBeanList(brandList, BrandDto.class);
    }

    @Override
    public Pager getPagerByCounts(int counts, int currentPage, int pageSize) {
        return brandService.getPagerByCounts(counts, currentPage, pageSize);
    }

    @Override
    public void deleteById(int id) {
        brandService.deleteById(id);
    }

    @Override
    public BrandDto getById(int id) {
        Brand brand = brandService.findById(id);
        return ShopBeanBuildUtil.slmCopyBean(brand, BrandDto.class);
    }

    @Override
    public void save(BrandDto brandDto) {
        Brand brand = ShopBeanBuildUtil.slmCopyBean(brandDto, Brand.class);
        brandService.save(brand);
    }

    @Override
    public void update(BrandDto brandDto) {
        Brand brand = ShopBeanBuildUtil.slmCopyBean(brandDto, Brand.class);
        brandService.update(brand);
    }

    @Override
    public int getTotalPage(int counts, int pageSize) {
        return brandService.getTotalPage(counts, pageSize);
    }
}
